import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { CrossStairRankRenderer } from "./CrossStairRankRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { SCrossStairRanks } from "../../../../../Message/Public/SCrossStairRanks";
import { GameProxy } from "../../../mvc/GameProxy";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class CrossStairRankingPanel
    
    export  class CrossStairRankingPanel extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(408, 405);
            title = Language.getString(60826);
            titleHeight = 25;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(16, 35, 376, 325, this);
            ObjCreate.createGTextField(Language.getString(60830), 18, 40, 50, 20, this, new GTextFormat(null, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            ObjCreate.createGTextField(Language.getString(60831), 68, 40, 160, 20, this, new GTextFormat(null, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            ObjCreate.createGTextField(Language.getString(60832), 228, 40, 65, 20, this, new GTextFormat(null, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            ObjCreate.createGTextField(Language.getString(60839), 293, 40, 85, 20, this, new GTextFormat(null, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._rankingList = ObjCreate.createTileList(18, 62, 372, 305, this);
            this._rankingList.columnWidth = 372;
            this._rankingList.rowHeight = 30;
            this._rankingList.setStyle("cellRenderer", CrossStairRankRenderer);
            this._rankingData = new DataProvider();
            this._rankingList.dataProvider = this._rankingData;
            this._myRankBtn = ObjCreate.createGButton(Language.getString(60828), 25, 365, 66, 26, this);
            this._myRankBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onMyRankBtnClick);
            this._pageSelec = ObjCreate.createPageSelecter(145, 370, this, PageSelecter.CompleteMode);
            this._pageSelec.addEventListener(flash.events.Event.CHANGE, this.onPageSelecChange);
            this._leaveBtn = ObjCreate.createGButton(Language.getString(60829), 305, 365, 66, 26, this);
            this._leaveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLeaveBtnClick);
            return;
        }

        public updateRankingData(arg1: SCrossStairRanks): void
        {
            this._pageSelec.maxPage = arg1.totalPage;
            this._pageSelec.currentPage = arg1.targetPage;
            this._rankingData.removeAll();
            this._rankingData.addItems(arg1.crossStairRanks);
            this._rankingList.dataProvider = this._rankingData;
            return;
        }

        /* internal  */onMyRankBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            GameProxy.copy.getCrossStairRank(this.PAGE_SIZE, 1, true);
            return;
        }

        /* internal  */onPageSelecChange(arg1: Object /* flash.events.Event */): void
        {
            this.getRank();
            return;
        }

        public getRank(): void
        {
            GameProxy.copy.getCrossStairRank(this.PAGE_SIZE, this._pageSelec.currentPage, false);
            return;
        }

        /* internal  */onLeaveBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuitCopy));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (!this._timer) 
            {
                this._timer = new SecTimer();
                this._timer.addListener(flash.events.TimerEvent.TIMER, this.onTimerEvent);
            }
            this._timer.start();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._timer) 
            {
                this._timer.dispose();
                this._timer = null;
            }
            return;
        }

        /* internal  */onTimerEvent(arg1: SecTimer): void
        {
            if (arg1.currentCount % 5 == 0) 
            {
                this.getRank();
            }
            return;
        }

        /* internal */ /* const */PAGE_SIZE: int=10;

        /* internal */ /* var */_rankingData: DataProvider;

        /* internal */ /* var */_rankingList: GTileList;

        /* internal */ /* var */_pageSelec: PageSelecter;

        /* internal */ /* var */_myRankBtn: GButton;

        /* internal */ /* var */_leaveBtn: GButton;

        /* internal */ /* var */_timer: SecTimer;
    }
